package cn.itcast.io.test;

import java.util.Objects;

public class Student implements Comparable<Student> {

    private String studentName;
    private int chinese;
    private int english;
    private int math;
    private int sum;

    public Student() {
    }

    public Student(String studentName, int chinese, int english, int math) {
        this.studentName = studentName;
        this.chinese = chinese;
        this.english = english;
        this.math = math;
        this.sum = chinese + english + math;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    public int getEnglish() {
        return english;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getSum() {
        return sum;
    }

    public void setSum(int sum) {
        this.sum = sum;
    }

    @Override
    public String toString() {
        return "Student{" +
                "studentName='" + studentName + '\'' +
                ", chinese=" + chinese +
                ", english=" + english +
                ", math=" + math +
                ", sum=" + sum +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Student)) return false;

        Student student = (Student) o;

        if (getChinese() != student.getChinese()) return false;
        if (getEnglish() != student.getEnglish()) return false;
        if (getMath() != student.getMath()) return false;
        if (sum != student.sum) return false;
        return getStudentName().equals(student.getStudentName());
    }

    @Override
    public int hashCode() {
        int result = getStudentName().hashCode();
        result = 31 * result + getChinese();
        result = 31 * result + getEnglish();
        result = 31 * result + getMath();
        result = 31 * result + sum;
        return result;
    }

    @Override
    public int compareTo(Student o) {
        int temp = this.sum - o.sum;
        return temp == 0 ? this.studentName.compareTo(o.studentName) : temp;
    }
}
